<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;


use App\Component\SwooleTable;
use Swoole\Table;

class ServerCallback
{

    /**
     * swoole服务启动前创建swooleTable
     */
    public function onBeforeStart()
    {
        SwooleTable::getInstance()->add(
            'fd_uid',
            ['uid' => [
                'type' => Table::TYPE_INT,
                'size' => 4]
            ],
            65536
        );
        SwooleTable::getInstance()->add(
            'uid_fd',
            ['fd' => [
                'type' => Table::TYPE_STRING,
                'size' => 32]
            ],
            65536
        );
        //清空redis中uid的绑定信息（不在server close中去清除，是因为kill -9杀死进程不会触发server close事件）
        \App\Component\UidBand::getInstance()->clear();
    }

}
